package logic

import (
	"Wei-Xin/weixinrpc/weixinrpcclient"
	"context"

	"Wei-Xin/api/internal/svc"
	"Wei-Xin/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MomentAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMomentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MomentAddLogic {
	return &MomentAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MomentAddLogic) MomentAdd(req *types.MomentAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.WeiXinRpc.MomentAdd(l.ctx, &weixinrpcclient.MomentAddRequest{
		Content: req.Content,
		UserId:  int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "发布成功",
		Data:    add,
		Code:    200,
	}, nil
}
